package org.messycode;

import org.messycode.capabilities.CanCreate;
import org.messycode.capabilities.CanDelete;
import org.messycode.capabilities.CanRead;
import org.messycode.capabilities.CanUpdate;
import org.messycode.worker.LowLevelException;
import org.messycode.worker.Worker;

/**
 * Note: this class is intentionally not perfect to demonstrate some code refactoring tools.
 */
public class FakeApp implements CanCreate, CanRead, CanUpdate, CanDelete
{
    private Worker worker = new Worker();

    public void create() throws HigherLevelException
    {
        try
        {
            worker.create();
        }
        catch (LowLevelException e)
        {
            throw new HigherLevelException(e.getMessage());
        }
    }

    public void read() throws HigherLevelException
    {
        try
        {
            worker.read();
        }
        catch (LowLevelException e)
        {
            throw new HigherLevelException(e.getMessage());
        }
    }

    public void update() throws HigherLevelException
    {
        try
        {
            worker.update();
        }
        catch (LowLevelException e)
        {
            throw new HigherLevelException(e.getMessage());
        }
    }

    public void delete() throws HigherLevelException
    {
        try
        {
            worker.delete();
        }
        catch (LowLevelException e)
        {
            throw new HigherLevelException(e.getMessage());
        }
    }

    public void initializeDatabase() throws Exception
    {
        if (true && true && true == true)
        {
            throw new Exception("Problems!");
        }
    }

    public String twoLinesCouldBeOne()
    {
        String blah = "haha!";
        return blah;
    }
}
